package com.catarc.unityback.entity.constant;


/**
 * @author van
 * 返回代号
 */
public enum ResultCode {
    /**
     * every fail download fail
     */
    DOWNLOAD_FAIL("download.fail", "下载失败"),

    /**
     * drop something fail
     */
    DROP_FAIL("drop.fail", "删除操作失败"),

    /**
     * result fail
     */
    FAIL("500", "fail"),

    /**
     * 400
     */
    BAD_REQUEST("400", "bad request"),

    /**
     * login fail
     */
    LOGIN_FAIL("login.fail", "登录失败"),

    /**
     * not found 资源未找到
     */
    NOT_FOUND("404", "not found"),

    /**
     * result success
     */
    SUCCESS("200", "success"),

    /**
     * error
     */
    SYSTEM_ERROR("system.error", "系统异常"),

    /**
     * every fail upload fail
     */
    UPLOAD_FAIL("upload.fail", "上传失败"),
    /**
     * 文件IO异常
     */
    FILE_IO_ERROR("file.io.error", "文件IO异常"),


    /**
     * 参数校验异常
     */
    CONSTRAINT_ILLEGAL("CONSTRAINT_ILLEGAL", "参数异常"),
    /**
     * 账号异常
     */
    ACCOUNT_ILLEGAL("ACCOUNT_ILLEGAL", "账号异常"),
    /**
     * 账户不存在(主要用于微信登录校验)
     */
    ACCOUNT_NOT_FOUND("ACCOUNT_NOT_FOUND", "账户不存在"),
    /**
     * 密码错误
     */
    PASSWORD_ERROR("PASSWORD_ERROR", "密码错误"),
    /**
     * 验证码错误
     */
    VERIFICATION_CODE_ERROR("VERIFICATION_CODE_ERROR", "验证码错误"),
    /**
     * 超时异常,主要用于爬虫时间处理
     */
    CRAWLER_OVERTIME_ERROR("CRAWLER_OVERTIME_ERROR", "超过规定爬取时间"),


    /**
     * 短信验证码十分钟内有效,请使用上一条短信验证码
     */
    VERIFICATION_HAS_SENT("verification.has.sent", "短信验证码十分钟内有效,请使用上一条短信验证码"),
    /**
     * Token验证失败,请确认Token来源是否为IDASS
     */
    IDAAS_TOKEN_VERIFY_ERROR("idaas.token.verify.error", "Token验证失败,请确认Token来源是否为IDASS"),
    /**
     * 通用业务异常,用于前端指定特殊异常处理
     */
    BIZ_ERROR("biz.error", "业务异常");

    private final String code;
    private final String msg;

    /**
     * constructor
     */
    ResultCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultCode getEnum(String id) {
        for (ResultCode num : ResultCode.values()) {
            if (num.code.equals(id)) {
                return num;
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
